package com.zhuss.repair.processor;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.food.food.CreateFoodBo;
import com.zhuss.bean.bo.repair.repair.CreateRepairBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.repair.db.dao.ext.RepairDao;
import com.zhuss.repair.db.entity.Repair;
import com.zhuss.util.JsonUtil;
import com.zhuss.util.NoUtil;

/**
 * 创建餐品 processor
 * @Author: zhushanshuo
 * @Date: 2020/02/28 16:01
 */
@Component("repairCreate")
public class RepairCreate extends AbstractProcessor<Object, CreateRepairBo> implements Processor<Object, CreateRepairBo> {

    @Autowired
    private RepairDao repairDao;
    
    @Autowired
	@Qualifier("repairRead")
	private RepairRead repairRead;
    
    
    /**
     * 校验
     */
    @Override
    public void check(CreateRepairBo bo) throws WpsException {
    	String repair_content = bo.getRepair_content();
    	String tel = bo.getTel();
    	if (repair_content == null || "".equals(repair_content.trim())) {
    		throw new WpsException(ExceptionCode.报修内容为空);
    	}
    	if (tel == null || "".equals(tel.trim())) {
    		throw new WpsException(ExceptionCode.报修联系方式为空);
    	}
    	/*List<Repair> list = foodRead.list(name, area);
    	if (!list.isEmpty()) {
    		throw new WpsException(ExceptionCode.餐品name已存在);
    	}*/
    }
    
    

    
    /**
     * 操作方法
     */
    @Override
    public Object process(CreateRepairBo param) {
    	Repair record = new Repair();
    	record.setRepair_userId(param.getRepair_userId());	//param.getConcurrentUserId()
    	record.setRepair_deptId(repairDao.getCompanyIdByUserId(param.getRepair_userId()));//param.getConcurrentCompanyId().intValue()
    	record.setTel(param.getTel());
    	record.setRepair_content(param.getRepair_content());
    	record.setRepair_files(param.getRepair_files());
    	record.setArea(param.getArea());
    	record.setNo_num(repairRead.getRepairNo());
    	record.setStatus(param.getStatus());
    	repairDao.create(record);
    	/*param.setTargetId(record.getFoodId());*/
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(CreateRepairBo param) throws WpsException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.报修登记.key());
    	record.setAction(LogActionEnum.报修创建.key());
    	record.setTargetId(param.getTargetId());
    	/*record.setTargetName(param.getName());*/
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}

}
